package cn.newtouch._06_oneway;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

public class Producer {

    public static void main(String[] args) throws Exception {
        //1.获取生产者对象
        DefaultMQProducer producer = new DefaultMQProducer("oneway_producer_group");
        //2.设置namesever地址
        producer.setNamesrvAddr("localhost:9876");
        //3.启动
        producer.start();
        //4.生成消息并发送
        Message message = new Message("oneway", "hello", "天天写bug!!好开心！！".getBytes(StandardCharsets.UTF_8));
        //单向发送
        producer.sendOneway(message);
        System.out.println("已单向发送消息！！");
        //5.关闭
        producer.shutdown();
    }
}
